package com.lmx.project.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lmx.project.model.dto.studyrecords.StudyrecordsQueryRequest;
import com.lmx.project.model.entity.Studyrecords;
import com.lmx.project.model.vo.StudyrecordsVo;
import com.lmx.project.service.StudyrecordsService;
import com.lmx.project.mapper.StudyrecordsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Lenovo
 * @description 针对表【studyRecords(学习记录表)】的数据库操作Service实现
 * @createDate 2023-04-07 22:36:34
 */
@Service
public class StudyrecordsServiceImpl extends ServiceImpl<StudyrecordsMapper, Studyrecords>
        implements StudyrecordsService {


    @Resource
    private StudyrecordsMapper studyrecordsMapper;

    @Override
    public Page<StudyrecordsVo> getstudurecordsByCondition(StudyrecordsQueryRequest studyrecordsQueryRequest) {

        long current = studyrecordsQueryRequest.getCurrent();
        long pageSize = studyrecordsQueryRequest.getPageSize();

        current = (current - 1) * pageSize;

        studyrecordsQueryRequest.setCurrent(current);
//     查询总数
        Long count=studyrecordsMapper.countStudyrecord(studyrecordsQueryRequest);
//         先查询条件
        List<StudyrecordsVo> list = studyrecordsMapper.selectstudurecords(studyrecordsQueryRequest);

        Page<StudyrecordsVo> studyrecordsPage = new Page<>();

        studyrecordsPage.setRecords(list);

        studyrecordsPage.setTotal(count);


        return studyrecordsPage;

    }
}




